<template>
  <div class="app">
    <van-nav-bar :title="title == '注册' ? '注册账号' : '面经登录'" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="请输入用户名"
        :error="false"
        :rules="[
          { required: true, message: '请填写用户名' },
          { pattern: /^[A-Za-z0-9]{6,8}$/, message: '用户名格式不正确' },
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="请输入密码"
        :error="false"
        :rules="[
          { required: true, message: '请填写密码' },
          { pattern: /^[A-Za-z0-9]{6,6}$/, message: '密码格式不正确' },
        ]"
      />
      <div style="margin: 16px">
        <van-button
          :round="false"
          block
          type="info"
          native-type="submit"
          :color="title == '注册' ? 'skyblue' : 'orange'"
          >{{ title }}</van-button
        >
      </div>
    </van-form>
    <!-- 插槽 -->
    <slot></slot>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      username: "",
      password: "",
    };
  },
  created() {
    // 暂时测试
    this.username = this.$route.query.username;
    this.password = this.$route.query.password;
  },
  methods: {
    onSubmit(values) {
      this.$emit("submit", values);
    },
  },
};
</script>

<style scoped>
.box {
  display: flex;
  justify-content: end;
  margin-right: 7px;
}
.link-right {
  font-size: 13px;
}
</style>